package com.zjw.zy.heart.control;

import com.zjw.zy.heart.bean.response.BaseResponse;
import com.zjw.zy.heart.domain.AppUiMode;
import com.zjw.zy.heart.service.impl.AppUIModeService;
import com.zjw.zy.heart.utils.CrashUtils;
import com.zjw.zy.heart.utils.LogUtils;
import lombok.NonNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/cloud")
public class CloudControl {
    private AppUIModeService appUIModeService;

    private static final String TAG = "CloudControl";


    @GetMapping("/crash/msg")
    public BaseResponse<String> uploadCrash(@RequestParam("crash") String crash, @RequestParam("time") String time) {
        LogUtils.e(TAG, "crash !!! time " + time + " crash->" + crash);

        CrashUtils.save(time, crash);
        return BaseResponse.ofSuccess("上报成功");
    }

    @GetMapping("/app/style/ui_mode")
    public BaseResponse<AppUiMode> applyAppUiMode() {
        LogUtils.d(TAG, "applyAppStyleMode");
        return BaseResponse.ofSuccess(appUIModeService.requireAppUIMode());
    }

    @GetMapping("/app/style/ui_mode/update")
    public BaseResponse<String> updateAppUiMode(@RequestParam(defaultValue = "0", name = "colorStyle") int colorStyle) {
        LogUtils.d(TAG, "testUpdate");
        boolean success = appUIModeService.updateAppUIMode(colorStyle);
        return success ? BaseResponse.ofSuccess("修改成功 " + colorStyle) : BaseResponse.ofFailed("修改失败!");
    }

    @Autowired
    public void setAppUIModeService(@NonNull AppUIModeService appUIModeService) {
        this.appUIModeService = appUIModeService;
    }
}
